home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / glibc-1.09 / glibc-1 / glibc-1.09.1 / sysdeps / mach / hurd / __getdents.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-18  |  1.7 KB  |  59 lines

  1. /* Copyright (C) 1992, 1993, 1994 Free Software Foundation, Ince    
  2.  
  3. This file is part of the GNU C Library.
  4.  
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. License, or (at your option) any later version.
  9.  
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with the GNU C Library; see the file COPYING.LIB.  If
  17. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  18. Cambridge, MA 02139, USA.  */
  19.  
  20. #include <ansidecl.h>
  21. #include <stddef.h>
  22. #include <errno.h>
  23. #include <sys/types.h>
  24. #include <hurd.h>
  25. #include <hurd/fd.h>
  26.  
  27. ssize_t
  28. DEFUN(__getdirentries, (fd, buf, nbytes, basep),
  29.       int fd AND PTR buf AND size_t nbytes AND off_t *basep)
  30. {
  31.   error_t err;
  32.   int entriesread;
  33.   char *data = buf;
  34.   mach_msg_type_number_t bytesread = nbytes;
  35.  
  36.   /* Fault before taking any locks.  */
  37.   *(volatile off_t *) basep = *basep;
  38.  
  39.   err = HURD_DPORT_USE (fd, __dir_readdir (port, &data, &bytesread,
  40.                        *basep, -1, nbytes, &entriesread));
  41.   if (err)
  42.     return __hurd_dfail (fd, err);
  43.  
  44.   if (data != buf)
  45.     {
  46.       size_t copy = bytesread;
  47.       if (copy > nbytes)
  48.     /* The server has a violated the dir_readdir protocol.  */
  49.     copy = nbytes;
  50.       memcpy (buf, data, copy);
  51.       __vm_deallocate (__mach_task_self (), (vm_address_t) data, bytesread);
  52.       bytesread = copy;
  53.     }
  54.  
  55.   *basep += entriesread;
  56.  
  57.   return bytesread;
  58. }
  59.